package com.example.demo.controller;

import com.example.demo.dao.CarDao;
import com.example.demo.model.Car;
import com.example.demo.model.Point;
import com.example.demo.model.PointFlag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/try")
@EnableAutoConfiguration
public class CarController {
    @Autowired
    private CarDao carDao;
    @GetMapping(value = "/car")
    public List<Car> getAllCars(){
        return carDao.selectCars();
    }
    @GetMapping(value = "/car/time")
    public List<List<Car>> getCarsByTime(){
        List<List<Car>> result=new ArrayList<>();
        String[] timeSection={"2008-02-02 13:00:00","2008-02-02 14:00:00","2008-02-02 15:00:00","2008-02-02 16:00:00","2008-02-02 17:00:00",};
        for (int i = 0; i <timeSection.length-1 ; i++) {
            Map<String,Timestamp> map=new HashMap<String, Timestamp>();
            map.put("time_s",Timestamp.valueOf(timeSection[i]));
            map.put("time_e",Timestamp.valueOf(timeSection[i+1]));
            result.add(carDao.queryTime(map));
        }
        return result;
    }
    @GetMapping(value = "/car/single")
    public List<Point> querySingle(){
        return carDao.querySingle();
    }
    @GetMapping(value = "/car/large")
    public List<Car> getAllCarsLarge(){
        return carDao.selectCarsLarge();
    }
    @GetMapping(value = "/car/cluster")
    public List<PointFlag> queryCluster(){
        return carDao.queryCluster();
    }
    @GetMapping(value = "/car/spot")
    public List<PointFlag> querySpot(){
        return carDao.querySpot();
    }

}
